package com.ruoyi.project.rest.statistics.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.project.rest.goods.domain.RestGoods;
import com.ruoyi.project.rest.goods.mapper.RestGoodsMapper;
import com.ruoyi.project.rest.member.domain.RestMember;
import com.ruoyi.project.rest.member.mapper.RestMemberMapper;
import com.ruoyi.project.rest.order.domain.RestOrder;
import com.ruoyi.project.rest.order.mapper.RestOrderMapper;
import com.ruoyi.project.rest.trade.domain.RestMemberTrade;
import com.ruoyi.project.rest.trade.mapper.RestMemberTradeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.rest.statistics.mapper.RestStatisticsDataMapper;
import com.ruoyi.project.rest.statistics.domain.RestStatisticsData;
import com.ruoyi.project.rest.statistics.service.IRestStatisticsDataService;
import com.ruoyi.common.utils.text.Convert;

/**
 * 统计数据Service业务层处理
 *
 * @author jfj
 * @date 2022-04-08
 */
@Service
public class RestStatisticsDataServiceImpl implements IRestStatisticsDataService {
    @Autowired
    private RestOrderMapper restOrderMapper;
    @Autowired
    private RestMemberMapper restMemberMapper;
    @Autowired
    private RestGoodsMapper restGoodsMapper;
    @Autowired
    private RestMemberTradeMapper restMemberTradeMapper;
    @Autowired
    private RestStatisticsDataMapper restStatisticsDataMapper;

    /**
     * 查询统计数据
     *
     * @param id 统计数据主键
     * @return 统计数据
     */
    @Override
    public RestStatisticsData selectRestStatisticsDataById(Long id) {
        return restStatisticsDataMapper.selectRestStatisticsDataById(id);
    }

    /**
     * 查询统计数据列表
     *
     * @param restStatisticsData 统计数据
     * @return 统计数据
     */
    @Override
    public List<RestStatisticsData> selectRestStatisticsDataList(RestStatisticsData restStatisticsData) {
        return restStatisticsDataMapper.selectRestStatisticsDataList(restStatisticsData);
    }

    /**
     * 新增统计数据
     *
     * @param restStatisticsData 统计数据
     * @return 结果
     */
    @Override
    public int insertRestStatisticsData(RestStatisticsData restStatisticsData) {
        return restStatisticsDataMapper.insertRestStatisticsData(restStatisticsData);
    }

    /**
     * 修改统计数据
     *
     * @param restStatisticsData 统计数据
     * @return 结果
     */
    @Override
    public int updateRestStatisticsData(RestStatisticsData restStatisticsData) {
        return restStatisticsDataMapper.updateRestStatisticsData(restStatisticsData);
    }

    /**
     * 批量删除统计数据
     *
     * @param ids 需要删除的统计数据主键
     * @return 结果
     */
    @Override
    public int deleteRestStatisticsDataByIds(String ids) {
        return restStatisticsDataMapper.deleteRestStatisticsDataByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除统计数据信息
     *
     * @param id 统计数据主键
     * @return 结果
     */
    @Override
    public int deleteRestStatisticsDataById(Long id) {
        return restStatisticsDataMapper.deleteRestStatisticsDataById(id);
    }

    @Override
    public RestStatisticsData selectMonthData(String startTime, String endDate) {
        return restStatisticsDataMapper.selectMonthData(startTime, endDate);
    }

    @Override
    public List<RestStatisticsData> selectDataList(String parseDateToStr, String date, Integer isTime) {
        return restStatisticsDataMapper.selectDataList(parseDateToStr, date, isTime);
    }

    @Override
    public AjaxResult getRecentData() {
        Map<String, Object> result = new HashMap<>();
        RestMember member = new RestMember();
        member.setOrderComlon("create_time desc");
        member.setLimitNum(3);
        List<RestMember> list = restMemberMapper.selectRestMemberList(member);

        RestGoods goods = new RestGoods();
        goods.setOrderComlon("create_time desc");
        goods.setLimitNum(3);
        List<RestGoods> goodsList = restGoodsMapper.selectRestGoodsList(goods);

        RestOrder order = new RestOrder();
        order.setOrderComlon("create_time desc");
        order.setLimitNum(3);
        order.setState(401);
        List<RestOrder> orderList = restOrderMapper.selectRestOrderList(order);

        RestMemberTrade memberTrade = new RestMemberTrade();
        memberTrade.setOrderComlon("create_time desc");
        memberTrade.setLimitNum(3);
        List<RestMemberTrade> tradeList = restMemberTradeMapper.selectRestMemberTradeList(memberTrade);
        result.put("goods", goodsList);
        result.put("member", list);
        result.put("order", orderList);
        result.put("trade", tradeList);
        return AjaxResult.success(result);
    }


}
